var e = require;
var t = module;
var n = exports;
"use strict";
var o,
t = this && this.__extends ||
  (o = function(e, t) {
    return (
      o = Object.setPrototypeOf ||
        {
          __proto__: []
        } instanceof Array &&
        function(e, t) {
          e.__proto__ = t;
        } ||
        function(e, t) {
          for (var n in t)
            Object.prototype.hasOwnProperty.call(t, n) && (e[n] = t[n]);
        }
    )(e, t);
  },
  function(e, t) {
    function n() {
      this.constructor = e;
    }
    o(e, t),
    e.prototype = null === t ? Object.create(t) : (n.prototype = t.prototype, new n());
  }
);
Object.defineProperty(n, "__esModule", { value: !0 });
n.OPPO = void 0;
var i,
t = (i = e("BasePlatform").BasePlatform,
  t(r, i),
  r.prototype.getInstance = function() {
    return this.sdk;
  },
  r.prototype.showRewardAds = function(e) {
    var t = this;
    return this.sdk.createRewardedVideoAd ?
      this._config.rewardID ?
        (this._rewardAdsCb = e,
          this._rewardHasShow = !1,
          this._rewardAds ||
          (this._rewardAds = this.sdk.createRewardedVideoAd({ adUnitId: this._config.rewardID }),
            this._rewardAds.onLoad(function() {
              t._rewardHasLoad = !0,
                t._rewardHasShow || (t._rewardHasShow = !0, t._rewardAds.show());
            }),
            this._rewardAds.onClose(function(e) {
              t._rewardHasLoad = !1,
                t._rewardAdsCb && (t._rewardAdsCb(e.isEnded ? 0 : 1), t._rewardAdsCb = null);
            }),
            this._rewardAds.onError(function(e) {
              t._rewardHasLoad = !1,
                console.log("[platform] [OPPOPlatform] showRewardAds", e),
                t._rewardAdsCb && (t._rewardAdsCb(-1), t._rewardAdsCb = null);
            })),
          void(this._rewardHasLoad && !this._rewardHasShow ? (this._rewardHasShow = !0, this._rewardAds.show()) : this._rewardAds.load())) : e(-3) : e(-2);
  },
  r.prototype.showBanner = function(e, t) {
    console.error("showBanner showBanner");
    void 0 === e && (e = { id: "" });
    this.sdk.createBannerAd && this._config.bannerID &&
      (this._banner ||
        (this._banner = this.sdk.createBannerAd({ adUnitId: e.id || this._config.bannerID }),
          console.log("[platform] [OPPOPlatform] create"),
          this._banner.show().then(function() {
            t && t(0);
          }).catch(function() {
            t && t(1);
          }),
          this._banner.onError(function(e) {
            console.log("[platform] [OPPOPlatform] showBanner", e);
          })));
  },
  r.prototype.hideBanner = function() {
    this._banner && (this._banner.destroy(), this._banner = null);
  },
  r.prototype.showNativeAds = function(t, n) {
    var o,
      i = this;
    void 0 === t && (t = { type: 0, container: null });
    this.sdk.createNativeAd && this._config.nativeID &&
      (o = this.sdk.createNativeAd({ adUnitId: t.id || this._config.nativeID }),
        t.container.opacity = 255,
        this._nativeAds.push({ ads: o, container: t.container }),
        o.onLoad(function(e) {
          e = e.adList ? e.adList[0] : null;
          0 != t.container.opacity &&
            (o && e &&
              (o.reportAdShow({ adId: e.adId }),
                0 == t.type ? i.showNativeBanner(e, o, t) : 1 == t.type ? i.showNativeInsert(e, o, t) : i.showNativeIcon(e, o, t)),
              o.offError(),
              o.offLoad()),
            n && n(0);
        }),
        o.onError(function(e) {
          console.log("[platform] [OPPOPlatform] showNativeAd", e),
            t.container && (t.container.active = !1, t.container.opacity = 0, -1 != (e = i._nativeAds.findIndex(function(e) {
              return e.container.name == t.container.name;
            })) && i._nativeAds.splice(e, 1)),
            o.offError(),
            o.offLoad(),
            o.destory && o.destory(),
            o = null,
            n && n(1);
        }),
        o && o.load());
  },
  r.prototype.hideNativeAds = function() {
    var e,
      t;
    this._nativeAds.length &&
      (e = this._nativeAds.pop(),
        cc.isValid(e.container, !0) && (e.container.opacity = 0, e.container.active = !1, e.container.off(cc.Node.EventType.TOUCH_START),
          (t = e.container.getChildByName("close")) && t.off(cc.Node.EventType.TOUCH_START),
          (t = e.container.getChildByName("next")) && t.off(cc.Node.EventType.TOUCH_START)),
        e.ads.destory && e.ads.destory());
  },
  r.prototype.showNativeBanner = function(e, t, n) {
    var o = this,
      i = (n = void 0 === n ? { type: 0, container: null } : n).container,
      r = i.getChildByName("img") || i.getChildByName("mask").getChildByName("img"),
      y = i.getChildByName("title"),
      a = i.getChildByName("desc"),
      s = i.getChildByName("btnText"),
      c = i.getChildByName("close");
    i.active = !0,
      i.once(cc.Node.EventType.TOUCH_START, function() {
        t.reportAdClick({ adId: e.adId }),
          o.hideNativeAds(),
          n.hideCb && n.hideCb();
      }, this),
      c && c.once(cc.Node.EventType.TOUCH_START, function() {
        n.isMistakeClose && t.reportAdClick({ adId: e.adId }),
          o.hideNativeAds(),
          n.hideCb && n.hideCb();
      }),
      y && (y.getComponent(cc.Label).string = "" + e.title),
      a && (a.getComponent(cc.Label).string = "" + e.desc),
      s && (s.getComponent(cc.Label).string = "" + (e.clickBtnTxt || "\u70b9\u51fb\u67e5\u770b")),
      r && (s = e.imgUrlList[Math.floor(Math.random() * e.imgUrlList.length)],
        cc.assetManager.loadRemote(s, { ext: ".png" }, function(e, t) {
          !e && r && (r.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(t));
        }));
  },
  r.prototype.showNativeInsert = function(e, t, n) {
    var o = this,
      i = (n = void 0 === n ? { type: 0, container: null } : n).container,
      r = i.getChildByName("img") || i.getChildByName("mask").getChildByName("img"),
      y = i.getChildByName("title"),
      a = i.getChildByName("desc"),
      s = i.getChildByName("btnText"),
      c = i.getChildByName("next"),
      x = i.getChildByName("close");
    i.active = !0,
      i.once(cc.Node.EventType.TOUCH_START, function() {
        t.reportAdClick({ adId: e.adId }),
          o.hideNativeAds(),
          n.hideCb && n.hideCb();
      }, this),
      c && c.once(cc.Node.EventType.TOUCH_START, function() {
        t.reportAdClick({ adId: e.adId }),
          o.hideNativeAds(),
          n.hideCb && n.hideCb();
      }, this),
      x && x.once(cc.Node.EventType.TOUCH_START, function() {
        console.log(n.isMistakeClose),
          n.isMistakeClose ? (console.log(1), t.reportAdClick({ adId: e.adId })) : console.log(2),
          o.hideNativeAds(),
          n.hideCb && n.hideCb();
      }),
      y && (y.getComponent(cc.Label).string = "" + e.title),
      a && (a.getComponent(cc.Label).string = "" + e.desc),
      s && (s.getComponent(cc.Label).string = "" + (e.clickBtnTxt || "\u70b9\u51fb\u67e5\u770b")),
      r && (s = e.imgUrlList[Math.floor(Math.random() * e.imgUrlList.length)],
        cc.assetManager.loadRemote(s, { ext: ".png" }, function(e, t) {
          !e && r && (r.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(t));
        }));
  },
  r.prototype.showNativeIcon = function(e, t, n) {
    var o = this,
      i = (n = void 0 === n ? { type: 0, container: null } : n).container,
      r = i.getChildByName("img") || i.getChildByName("mask").getChildByName("img"),
      y = i.getChildByName("title"),
      a = i.getChildByName("close");
    i.active = !0,
      i.once(cc.Node.EventType.TOUCH_START, function() {
        t.reportAdClick({ adId: e.adId }),
          o.hideNativeAds(),
          n.hideCb && n.hideCb();
      }, this),
      a && a.once(cc.Node.EventType.TOUCH_START, function() {
        n.isMistakeClose && t.reportAdClick({ adId: e.adId }),
          o.hideNativeAds(),
          n.hideCb && n.hideCb();
      }),
      y && (y.getComponent(cc.Label).string = "" + e.title),
      r && cc.assetManager.loadRemote(e.icon, { ext: ".png" }, function(e, t) {
        !e && r && (r.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(t));
      });
  },
  r);
function r() {
  var e = i.call(this) || this;
  return e.sdk = window.qg,
    e._rewardAds = null,
    e._rewardAdsCb = null,
    e._rewardHasShow = !1,
    e._rewardHasLoad = !1,
    e._banner = null,
    e._nativeAds = [],
    console.log("oppo"),
    e;
}
n.OPPO = t;
